from dataclasses import dataclass
import sys
import traceback
import enum

@dataclass(order=True)
class User:
    """
    dataclass 装饰器 省却了 __init__ 自动初始化相关属性
    """
    name: str
    age: int
    salary: float


user1 = User("caoyx",43,39999)
user2 = User("caoyx",43,39999)
user3 = User("jack",43,39999)
print(user1)
print(user1 == user2,id(user1),id(user2))
print(user1 >= user3,id(user1),id(user3))

# Frozen（不可变） 实例
@dataclass(frozen=True)
class Tax:
    tax_code: str
    tax_name: str

tax = Tax('10101','增值税')
print(tax)
#下面语句会报错,不允许修改
try:
    tax.tax_code = '10102'
except Exception as e:
    exc_type, exc_value, exc_obj = sys.exc_info()
    print("**********************************")
    traceback.print_tb(exc_obj)

class State(enum.Enum):
    IDEL = enum.auto()
    STARTED = enum.auto()
    PAUSED = enum.auto()


print(State.IDEL)
print(repr(State.IDEL))
print(repr(State.STARTED))
print(repr(State.PAUSED))